package api

import (
	"context"
	"gitee.com/kristas/booting-go/framework"
	"gitee.com/kristas/booting-go/framework/core/statement/types"
	"gitee.com/kristas/booting-go/framework/web/resp"
	"gitee.com/kristas/booting-go/framework/web/rest"
	"gitee.com/kristas/booting-go/internal/demo/dto"
	"gitee.com/kristas/booting-go/internal/demo/service"
)

func init() {
	framework.Component(new(AccountController))
}

type AccountController struct {
	types.Controller `group:"/api/v1/users"` //statement as `controller`, use `group` tag as mapping prefix
	service.Factory  `wire:"service_factory"`
	getAllUsers      rest.GET  `url:"" param:"[c context]" resp:"[]dto.AccountDTO" desc:"查询所有用户"`
	getUserById      rest.GET  `url:"/{username}" param:"c context,username path" resp:"dto.AccountDTO" desc:"按用户名查询用户"`
	saveUser         rest.POST `url:"/{username}/save" param:"c context, username path, user.dto.AccountDTO body" resp:"resp.Response" desc:"添加用户"`
}

// GetAllUsers associate with AccountController.getAllUsers
func (r *AccountController) GetAllUsers(ctx context.Context) ([]*dto.AccountDTO, error) {
	return r.GetAccountService().GetAllUsers(ctx)
}

// GetUserById associate with AccountController.getUserById
func (r *AccountController) GetUserById(ctx context.Context, username string) (*dto.AccountDTO, error) {
	return r.GetAccountService().GetUserById(ctx, username)
}

// SaveUser associate with AccountController.saveUser
func (r *AccountController) SaveUser(ctx context.Context, username string, employee *dto.AccountDTO) (resp.Response, error) {
	return r.GetAccountService().SaveUser(ctx, username, employee)
}
